package cn.kbyue.adminclientdemo.controller;

import cn.kbyue.adminclientdemo.entity.UserDTO;
import cn.kbyue.adminclientdemo.service.CacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xlang
 * @date 2023/4/4 14:59
 */
@RestController
@RequestMapping("/cache")
@RequiredArgsConstructor
public class CacheController {

    private final CacheService cacheService;

    @GetMapping("/save")
    public ResponseEntity<UserDTO> save(@RequestParam("id") Integer id) {
        UserDTO userDTO = cacheService.getById(id);
        return new ResponseEntity<>(userDTO, HttpStatus.OK);
    }

    @DeleteMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestParam("id") Integer id) {
        boolean deleted = cacheService.delete(id);
        return new ResponseEntity<>(deleted, HttpStatus.OK);
    }

}
